package com.umfb.config.zk;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * Created by zcah on 18-4-19.
 */
public class ZooKeeperFactory {
    public static final int MAX_RETRIES = 3;

    public static final int BASE_SLEEP_TIMEMS = 3000;

    public static CuratorFramework get(String zkServer, String zkNS) {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_TIMEMS, MAX_RETRIES);
        CuratorFramework client = CuratorFrameworkFactory.builder().connectString(zkServer).retryPolicy(retryPolicy)
                .namespace(zkNS).build();
        client.start();

        return client;
    }


}
